package cn.gson.tj_springboot.model.pojos;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;

@Entity
public class Role {
    private int roleId;
    private String roleName;
    private String roleTag;

    private List<Function> funs;

    @ManyToMany
    @JoinTable(name="function_role",
            joinColumns = {
                    @JoinColumn(name="role_id")
            },
            inverseJoinColumns = {
                    @JoinColumn(name="function_id")
            })
    public List<Function> getFuns() {
        return funs;
    }

    public void setFuns(List<Function> funs) {
        this.funs = funs;
    }

    @Id
    @Column(name = "role_id", nullable = false)
    public int getRoleId() {
        return roleId;
    }

    public void setRoleId(int roleId) {
        this.roleId = roleId;
    }

    @Basic
    @Column(name = "role_name", nullable = true, length = 255)
    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    @Basic
    @Column(name = "role_tag", nullable = true, length = 255)
    public String getRoleTag() {
        return roleTag;
    }

    public void setRoleTag(String roleTag) {
        this.roleTag = roleTag;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Role role = (Role) o;
        return roleId == role.roleId &&
                Objects.equals(roleName, role.roleName) &&
                Objects.equals(roleTag, role.roleTag);
    }

    @Override
    public int hashCode() {
        return Objects.hash(roleId, roleName, roleTag);
    }
}
